package org.wtj.service.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wtj.entity.ResponsePageEntity;
import org.wtj.entity.sys.SysDeptConditionEntity;
import org.wtj.entity.sys.SysDeptEntity;
import org.wtj.mapper.BaseMapper;
import org.wtj.mapper.sys.SysDeptMapper;
import org.wtj.service.BaseService;

import java.util.List;

/**
 * 部门 服务层
 *
 * @author wang 该项目是知识星球：java突击队 的内部项目
 * @date 2025-03-06 21:50:53
 */
@Service
public class SysDeptService extends BaseService<SysDeptEntity, SysDeptConditionEntity> {

	@Autowired
	private SysDeptMapper sysDeptMapper;

	/**
     * 查询部门信息
     *
     * @param id 部门ID
     * @return 部门信息
     */
	public SysDeptEntity findById(Long id) {
	    return sysDeptMapper.findById(id);
	}

	/**
     * 根据条件分页查询部门列表
     *
     * @param sysDeptConditionEntity 部门信息
     * @return 部门集合
     */
	public ResponsePageEntity<SysDeptEntity> searchByPage(SysDeptConditionEntity sysDeptConditionEntity) {
		int count = sysDeptMapper.searchCount(sysDeptConditionEntity);
		if (count == 0) {
			return ResponsePageEntity.buildEmpty(sysDeptConditionEntity);
		}
		List<SysDeptEntity> dataList = sysDeptMapper.searchByCondition(sysDeptConditionEntity);
		return ResponsePageEntity.build(sysDeptConditionEntity, count, dataList);
	}

    /**
     * 新增部门
     *
     * @param sysDeptEntity 部门信息
     * @return 结果
     */
	public int insert(SysDeptEntity sysDeptEntity) {
	    return sysDeptMapper.insert(sysDeptEntity);
	}

	/**
     * 修改部门
     *
     * @param sysDeptEntity 部门信息
     * @return 结果
     */
	public int update(SysDeptEntity sysDeptEntity) {
	    return sysDeptMapper.update(sysDeptEntity);
	}

	/**
     * 批量删除部门对象
     *
     * @param ids 系统ID集合
     * @return 结果
     */
	public int deleteByIds(List<Long> ids) {
		List<SysDeptEntity> entities = sysDeptMapper.findByIds(ids);

		SysDeptEntity entity = new SysDeptEntity();
		return sysDeptMapper.deleteByIds(ids, entity);
	}

	@Override
	protected BaseMapper getBaseMapper() {
		return sysDeptMapper;
	}

}
